package com.muyu.payment.domain;

import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import com.muyu.payment.domain.req.PaymentOrderQueryReq;
import com.muyu.payment.domain.model.PaymentOrderSaveModel;
import com.muyu.payment.domain.model.PaymentOrderEditModel;
import com.muyu.common.core.web.domain.BaseEntity;

/**
 * 支付订单数据库映射对象 payment_order
 *
 * @author muyu
 * @date 2025-09-16
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("payment_order")
@EqualsAndHashCode(callSuper = true)
public class PaymentOrder extends BaseEntity {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Long id;

    /**
     * 订单号
     */
    @Excel(name = "订单号")
    private String orderNo;

    /**
     * 用户ID
     */
    @Excel(name = "用户ID")
    private Long userId;

    /**
     * 订单金额
     */
    @Excel(name = "订单金额")
    private BigDecimal amount;

    /**
     * 订单状态(1:待支付,2:已支付,8:已关闭,9:已退款)
     */
    @Excel(name = "订单状态(1:待支付,2:已支付,8:已关闭,9:已退款)")
    private Long orderStatus;

    /**
     * 支付时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date payTime;

    /**
     * 支付渠道
     */
    @Excel(name = "支付渠道")
    private String payChannel;

    /**
     * 第三方交易号
     */
    @Excel(name = "第三方交易号")
    private String payTradeNo;


    /**
     * 订单标题
     */
    @Excel(name = "订单标题")
    private String subject;

    /**
     * 删除标志（0-未删除，1-已删除）
     */
    private Long delFlag;

    /**
     * 订单描述
     */
    @Excel(name = "订单描述")
    private String body;

    /**
     * 客户端IP (IPv4/IPv6)
     */
    @Excel(name = "客户端IP (IPv4/IPv6)")
    private String clientIp;

    /**
     * 异步通知地址
     */
    @Excel(name = "异步通知地址")
    private String notifyUrl;

    /**
     * 同步返回地址
     */
    @Excel(name = "同步返回地址")
    private String returnUrl;

    /**
     * 订单过期时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "订单过期时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date expireTime;
    /**
     * 创建时间时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "创建时间时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date createTime;
    /**
     * 订单更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "订单更新时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date updateTime;

    /**
     * 备注
     */
    @Excel(name = "备注")
    private String remark;
    /**
     * 创建者
     */
    @Excel(name = "创建者")
    private String createBy;
    /**
     * 修改者
     */
    @Excel(name = "修改者")
    private String updateBy;

    /**
     * 支付类型
     */
    @Excel(name = "支付类型")
    private Long payType;

    /**
     * 添加构造器
     */
    public static PaymentOrder saveModelBuild(PaymentOrderSaveModel saveModel){
        return PaymentOrder.builder()
                .orderNo(saveModel.getOrderNo())
                .userId(saveModel.getUserId())
                .amount(saveModel.getAmount())
                .orderStatus(saveModel.getOrderStatus())
                .payTime(saveModel.getPayTime())
                .payChannel(saveModel.getPayChannel())
                .payTradeNo(saveModel.getPayTradeNo())
                .subject(saveModel.getSubject())
                .body(saveModel.getBody())
                .clientIp(saveModel.getClientIp())
                .notifyUrl(saveModel.getNotifyUrl())
                .returnUrl(saveModel.getReturnUrl())
                .expireTime(saveModel.getExpireTime())
                .remark(saveModel.getRemark())
                .payType(saveModel.getPayType())
                .createBy(saveModel.getCreateBy())
                .updateBy(saveModel.getUpdateBy())
                .createTime(saveModel.getCreateTime())
                .updateTime(saveModel.getUpdateTime())
                .build();
    }

    /**
     * 修改构造器
     */
    public static PaymentOrder editModelBuild(PaymentOrderEditModel editModel){
        return PaymentOrder.builder()
                .id(editModel.getId())
                .orderNo(editModel.getOrderNo())
                .userId(editModel.getUserId())
                .amount(editModel.getAmount())
                .orderStatus(editModel.getOrderStatus())
                .payTime(editModel.getPayTime())
                .payChannel(editModel.getPayChannel())
                .payTradeNo(editModel.getPayTradeNo())
                .subject(editModel.getSubject())
                .body(editModel.getBody())
                .clientIp(editModel.getClientIp())
                .notifyUrl(editModel.getNotifyUrl())
                .returnUrl(editModel.getReturnUrl())
                .expireTime(editModel.getExpireTime())
                .remark(editModel.getRemark())
                .payType(editModel.getPayType())
                .createBy(editModel.getCreateBy())
                .updateBy(editModel.getUpdateBy())
                .createTime(editModel.getCreateTime())
                .updateTime(editModel.getUpdateTime())
                .build();
    }

}
